/**
 * Copyright (C), 2015-2021, 开度
 * FileName: JasyptController
 * Author:   ASUS
 * Date:     2021/8/18 14:51
 * Description: 私密编码加密
 * History:
 * <author>          <time>          <version>          <desc>
 * Hezeyu           2021/8/18           1.0              私密编码加密
 */
package com.example.spring.security.controller;

import com.example.spring.security.config.CustomStringEncryptor;
import com.example.spring.security.utils.BaseResponse;
import lombok.extern.slf4j.Slf4j;
import org.jasypt.encryption.StringEncryptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 〈私密编码加密〉
 *
 * @author Hezeyu
 * @create 2021/8/18
 * @since 1.0.0
 */
@RestController
@Slf4j
@RequestMapping("encrypt")
public class JasyptController {

    @Autowired
    CustomStringEncryptor encryptor;

    @Value("${jasypt.encryptor.property.prefix}")
    private String start;

    @Value("${jasypt.encryptor.property.suffix}")
    private String end;

    @GetMapping("/info")
    public BaseResponse encrypt(String password) {
        String encrypt = encryptor.encrypt(password);
        BaseResponse baseResponse = new BaseResponse();
        baseResponse.setSuccess("转换成功", start+encrypt+end, "");
        return baseResponse;
    }
}
